
<template>
  <!-- 账簿维护/智能录入 页面-->
  <div>

    <cus-allcard :showTitle="false" style="min-width:924px;">

      <Tabs :value="tabsValue" @on-click="tabsValueChange($event)" style="padding-top:16px;min-width:880px;">
        <Tab-pane label="经费账录入" name="nameOne">
          <div class="topBody">
            <div class="topBodyItem">
              <span class="itemSpan">账簿年度</span>
              <Input v-model="selectForm.year" class="itemImport" :disabled="true" placeholder="请输入账簿年度"
                maxlength="15"></Input>
            </div>
            <div class="topBodyItem">
              <span class="itemSpan">凭证号码</span>
              <Input v-model="selectForm.certificatesn" class="itemImport" :disabled="true" placeholder="请输入凭证号码"
                maxlength="15"></Input>
            </div>
            <!-- 暂时去掉 -->
            <div class="topBodyItem">
              <span class="itemSpan">业务类型</span>
              <Select v-model="selectForm.businesstypeOne" placeholder="请选择业务类型" @on-change="selectModelChangeOne($event)"
                class="itemImport">
                <Option v-for="item in selectForm.businesstypeOneList" :value="item.abstractname" :key="item.abstractId">
                  {{ item.abstractname }}</Option>
              </Select>
            </div>

            <div class="topBodyItem">
              <span class="itemSpan">摘要内容</span>
              <Input v-model="selectForm.abstractnameOne" class="itemImport" placeholder="请输入摘要内容" maxlength="15"></Input>
            </div>
            <div class="topBodyItem">
              <span class="itemSpan">入账日期</span>
              <Date-picker type="date" :options="options" v-model="selectForm.dataTimeOne" :clearable="false"
                placeholder="请选择入账日期" class="itemImport"></Date-picker>
            </div>

            <!-- <div class="topBodyItem">
              <span class="itemSpan">备注信息：</span>
              <Input v-model="selectForm.remarkOne"
                     class="itemImport"
                     placeholder="请输入备注信息"
                     maxlength="15"></Input>
            </div> -->
            <!-- :formatter="value=>`${parseFloat(Math.floor(value*100)/100)}`" -->
            <!-- :active-change="false" -->
            <!-- :parser="value=>value.replace(/\$\s?|(,*)/g,'')" -->
            <!-- :formatter="value=>`${value}`.replace(/\B(?=(\d{3})+(?!\d))/g,',')" -->
            <div class="topBodyItem">
              <span class="itemSpan">收付金额</span>
              <Input-number v-model="selectForm.oneAllMoney" :disabled="dataOne.length == 0" :min="0" :max="999999999"
                :formatter="value => `${parseFloat(Math.floor(value * 100) / 100)}`" class="itemImport"
                @on-change="oneAllMoneyChange()" @blur="oneAllMoneyChange()" placeholder="输入金额"></Input-number>
            </div>
            <div class="topBodyItem">
              <cus-Button type="primary" :disabled="!selectForm.year" @onClick="addModelChangeOne" class="ml_20"
                v-permission="20">入账</cus-Button>
            </div>
          </div>
          <cusTable border :loading="form.loading" :columns="columnsOne" :data="dataOne" :customHeight="295"
            :size="vuex_config.tableSize">
            <template slot-scope="{ row }" slot="direction">
              {{ row.direction == 0 ? '收' : '付' }}
            </template>
            <template slot-scope="{ row }" slot="recMoney">
              {{ totalPrices(row.recMoney) }}
            </template>

            <template slot-scope="{ row }" slot="payMoney">
              {{ totalPrices(row.payMoney) }}
            </template>
          </cusTable>

        </Tab-pane>
        <Tab-pane label="粮秣账录入" name="nameTwo">
          <div class="topBody">
            <div class="topBodyItem">
              <span class="itemSpan">账簿年度</span>
              <Input v-model="selectForm.year" class="itemImport" :disabled="true" placeholder="请输入账簿年度"
                maxlength="15"></Input>
            </div>
            <div class="topBodyItem">
              <span class="itemSpan">凭证号码</span>
              <Input v-model="selectForm.certificatesn" class="itemImport" :disabled="true" placeholder="请输入凭证号码"
                maxlength="15"></Input>
            </div>
            <!-- 暂时去掉 -->
            <div class="topBodyItem">
              <span class="itemSpan">业务类型</span>
              <Select v-model="selectForm.businesstypeTwo" placeholder="请选择业务类型" @on-change="selectModelChangeTwo($event)"
                class="itemImport">
                <Option v-for="item in selectForm.businesstypeTwoList" :value="item.abstractname"
                  :key="item.abstractcode">{{ item.abstractname }}</Option>
              </Select>
            </div>
            <div class="topBodyItem">
              <span class="itemSpan">摘要内容</span>
              <Input v-model="selectForm.abstractnameTwo" class="itemImport" placeholder="请输入摘要内容" maxlength="15"></Input>
            </div>
            <div class="topBodyItem">
              <span class="itemSpan">入账日期</span>
              <Date-picker type="date" :options="options" v-model="selectForm.dataTimeTwo" :clearable="false"
                placeholder="请选择入账日期" class="itemImport"></Date-picker>
            </div>

            <!-- <div class="topBodyItem">
              <span class="itemSpan">备注信息：</span>
              <Input v-model="selectForm.remarkTwo"
                     class="itemImport"
                     placeholder="请输入备注信息"
                     maxlength="15"></Input>
            </div> -->
            <div class="topBodyItem">
              <span class="itemSpan">大米</span>
              <Input-number v-model="selectForm.twoAllRiceMoney" :disabled="dataTwo.length == 0" :min="0"
                :formatter="value => `${parseFloat(Math.floor(value * 100) / 100)}`" class="itemImport"
                @on-change="twoAllRiceMoneyChange()" placeholder="输入金额"></Input-number>
            </div>
            <div class="topBodyItem">
              <span class="itemSpan">小麦粉</span>
              <Input-number v-model="selectForm.twoAllFlourMoney" :disabled="dataTwo.length == 0" :min="0"
                :formatter="value => `${parseFloat(Math.floor(value * 100) / 100)}`" class="itemImport"
                @on-change="twoAllFlourMoneyChange()" placeholder="输入金额"></Input-number>
            </div>
            <div class="topBodyItem">
              <span class="itemSpan">食油</span>
              <Input-number v-model="selectForm.twoAllOilMoney" :disabled="dataTwo.length == 0" :min="0"
                :formatter="value => `${parseFloat(Math.floor(value * 100) / 100)}`" class="itemImport"
                @on-change="twoAllOilMoneyChange()" placeholder="输入金额"></Input-number>
            </div>
            <div class="topBodyItem">
              <span class="itemSpan">大豆</span>
              <Input-number v-model="selectForm.twoAllBeanMoney" :disabled="dataTwo.length == 0" :min="0"
                :formatter="value => `${parseFloat(Math.floor(value * 100) / 100)}`" class="itemImport"
                @on-change="twoAllBeanMoneyChange()" placeholder="输入金额"></Input-number>
            </div>
            <div class="topBodyItem">
              <cus-Button type="primary" :disabled="!selectForm.year" @onClick="addModelChangeTwo" class="ml_20"
                v-permission="20">入账</cus-Button>
            </div>
          </div>
          <cusTable border :loading="form.loading" :columns="columnsTwo" :data="dataTwo" :customHeight="330"
            :size="vuex_config.tableSize">
            <template slot-scope="{ row }" slot="direction">
              {{ row.direction == 0 ? '收' : '付' }}
            </template>
            <template slot-scope="{ row }" slot="recrice">
              {{ totalPrices(row.recrice) }}
            </template>

            <template slot-scope="{ row }" slot="recflour">
              {{ totalPrices(row.recflour) }}
            </template>

            <template slot-scope="{ row }" slot="recoil">
              {{ totalPrices(row.recoil) }}
            </template>
            <template slot-scope="{ row }" slot="recbean">
              {{ totalPrices(row.recbean) }}
            </template>

            <template slot-scope="{ row }" slot="payrice">
              {{ totalPrices(row.payrice) }}
            </template>
            <template slot-scope="{ row }" slot="payflour">
              {{ totalPrices(row.payflour) }}
            </template>
            <template slot-scope="{ row }" slot="payoil">
              {{ totalPrices(row.payoil) }}
            </template>
            <template slot-scope="{ row }" slot="paybean">
              {{ totalPrices(row.paybean) }}
            </template>

            <template slot-scope="{ row }" slot="remainrice">
              {{ totalPrices(row.remainrice) }}
            </template>
            <template slot-scope="{ row }" slot="remainflour">
              {{ totalPrices(row.remainflour) }}
            </template>
            <template slot-scope="{ row }" slot="remainoil">
              {{ totalPrices(row.remainoil) }}
            </template>
            <template slot-scope="{ row }" slot="remainbean">
              {{ totalPrices(row.remainbean) }}
            </template>
          </cusTable>

        </Tab-pane>
      </Tabs>

    </cus-allcard>
    <!-- 使用粘性定位 -->
    <div v-if="superiorState" class="sticky-button">
      <cus-Button class="mr_10" type="default" @onClick="returnHome">返回首页</cus-Button>
    </div>
  </div>
</template>
<script>
import {
  getAccountBook,
  getLastCertSn,
  getAbstractByAccountBookIdAndType,
  getSubjectToCertificate,
  addCertificateInfo,
  getSubByAbsId
} from '@/api/businessAccountingApi/essentialInformationApi'
export default {
  data() {
    return {
      superiorState: false,
      tabsValue: 'nameOne',
      options: {
        disabledDate: (date) => {
          let beginT = new Date(`${this.selectForm.year}-01-01`).getTime();
          let currentY = new Date().getFullYear();
          if (currentY == this.selectForm.year) {
            return date && (beginT - 86400000 > date.valueOf() || date.valueOf() >= Date.now());
          } else {
            let endT = new Date(`${parseInt(this.selectForm.year) + 1}-01-01`).getTime() - 86400000;
            return date && (beginT - 86400000 > date.valueOf() || date.valueOf() >= endT);
          }
        }
      },
      form: {
        loading: false,
        name: '',
        startTime: '',
        endTime: ''
      },
      // 查询条件的集合
      selectForm: {
        year: null, // 账簿时间
        accountbookId: null, // 账簿id
        department: null, // 部门名称
        certificatesn: null, // 凭证号码
        dataTimeOne: null, // 入账日期-经费账
        dataTimeTwo: null, // 入账日期-粮秣账
        businesstypeOneList: [], // 业务类型-经费账列表
        businesstypeOne: null, // 业务类型-经费账
        businesstypeTwoList: [], // 业务类型-粮秣账列表
        businesstypeTwo: null, // 业务类型-粮秣账
        abstractnameOne: null, // 摘要内容-经费账
        abstractnameTwo: null, // 摘要内容-粮秣账
        remarkOne: '', // 备注信息-经费账
        remarkTwo: '', // 备注信息-经费账
        abstractId: null,//业务类型id,
        oneAllMoney: null,//收付金额
        twoAllRiceMoney: null,//收付大米
        twoAllFlourMoney: null,//收付小麦粉
        twoAllOilMoney: null,//收付食油
        twoAllBeanMoney: null//收付大豆

      },

      subjecttype: 0, // 0经费账 1粮秣账
      // 经费账表格每次添加的初始模板
      dataOneItem: {
        subjectId: null, // 科目id
        subjectCode: null, // 科目编码
        subjectName: null, // 科目名称
        subjectFullName: null, //科目名称
        direction: null, // 收付(0-收，1-付)
        recMoney: 0, // 收方金额
        payMoney: 0 // 付方金额
      },
      dataOne: [], // 经费账-表格列表
      subjectlistOne: [], // 表格科目名称选择器列表 -经费账
      subjectlistTwo: [], // 表格科目名称选择器列表 -粮秣账
      // 经费账-表头
      columnsOne: [
        {
          title: '科目名称',
          key: 'subjectFullName',
          align: 'center',
          minWidth: 180
        },
        {
          title: '收(付)',
          slot: 'direction',
          align: 'center',
          minWidth: 80
        },
        {
          title: '收方金额(元)',
          slot: 'recMoney',
          align: 'right',
          minWidth: 120
        },
        {
          title: '付方金额(元)',
          slot: 'payMoney',
          align: 'right',
          minWidth: 120
        }
      ],
      // 粮秣表格每次添加的初始模板
      dataTwoItem: {
        subjectId: null, // 科目id
        subjectCode: null, // 科目编码
        subjectName: null, // 科目名称
        subjectFullName: null, //科目名称
        direction: null, // 收付(0-收，1-付)
        recrice: 0, // 收方大米重量（千克）粮秣账必传
        recflour: 0, // 收方小麦粉（千克） 粮秣账必传
        recoil: 0, // 收方石油（千克） 粮秣账必传
        recbean: 0, // 收付大豆（千克） 粮秣账必传
        payrice: 0, // 付方大米重量（千克） 粮秣账必传
        payflour: 0, // 付方小麦粉（千克） 粮秣账必传
        payoil: 0, // 付方石油（千克） 粮秣账必传
        paybean: 0 // 付方大豆（千克） 粮秣账必传
      },
      dataTwo: [], // 粮秣账-表格列表
      // 粮秣账-表头
      columnsTwo: [
        {
          title: '科目名称',
          key: 'subjectFullName',
          align: 'center',
          minWidth: 180
        },
        {
          title: '收(付)',
          slot: 'direction',
          align: 'center',
          minWidth: 100
        },
        {
          title: '收方(大米)',
          slot: 'recrice',
          align: 'right',
          minWidth: 120
        },
        {
          title: '收方(小麦粉)',
          slot: 'recflour',
          align: 'right',
          minWidth: 120
        },
        {
          title: '收方(食油)',
          slot: 'recoil',
          align: 'right',
          minWidth: 120
        },
        {
          title: '收方(大豆)',
          slot: 'recbean',
          align: 'right',
          minWidth: 120
        },
        {
          title: '付方(大米)',
          slot: 'payrice',
          align: 'right',
          minWidth: 120
        },
        {
          title: '付方(小麦粉)',
          slot: 'payflour',
          align: 'right',
          minWidth: 120
        },
        {
          title: '付方(食油)',
          slot: 'payoil',
          align: 'right',
          minWidth: 120
        },
        {
          title: '付方(大豆)',
          slot: 'paybean',
          align: 'right',
          minWidth: 120
        }
      ],
      subjectid: 0, // 删除经费账粮秣账接口传参id
      tableHeight: 0
    }
  },
  mounted() {
    setTimeout(() => {
      this.tableHeight = window.innerHeight - 64 - 40 - 16 - 37 - 16 - document.getElementsByClassName("topBody")[0].offsetHeight - 24 - 40// 表格自适应高度
    }, 100)
    window.addEventListener('resize', this.tableHeightChange, true)
    this.selectForm.dataTimeOne = new Date().Format('yyyy-MM-dd')
    this.selectForm.dataTimeTwo = new Date().Format('yyyy-MM-dd')
    this.getAccountBookApi() // 查询活动账簿 接口

    // 函数时提示变成3秒消失
    this.$Message.config({
      top: 50,
      duration: 3
    })
    // this.getAccountBookListByUserApi() // 根据用户id查询账簿-选择器使用
    // this.getAllSubjectApi(0)// 默认查经费账     // 获取 经费账录入 或 粮秣账录入
  },
  // 销毁函数时提示变回1.5秒消失
  beforeDestroy() {
    this.$Message.config({
      top: 50,
      duration: 1.5
    })
  },
  destroyed() {
    window.removeEventListener('resize', this.tableHeightChange, true)
  },
  activated() {
    if (this.$route.query.superior == 'home') {
      this.superiorState = true
    } else {
      this.superiorState = false
    }
  },
  methods: {
    // 千位分割符
    totalPrices(recmoney) {
      const intPart = Math.trunc(recmoney)//整数部分
      let floatPart = 0
      const intPartFormat = intPart.toString().replace(/\B(?=(\d{3})+$)/g, ',')
      const valuArray = Number(recmoney).toString().split('.')

      if (valuArray.length === 2) {//有小数部分
        if (valuArray[1]) {
          if (valuArray[1].length === 1) {
            valuArray[1] += '0'
          }
        } else {
          valuArray[1] = '00'
        }
        floatPart = valuArray[1]//取得小数部分

        return intPartFormat + '.' + floatPart
      } else {
        return intPartFormat + '.00'
      }
    },
    tableHeightChange() {
      this.tableHeight = 0
      setTimeout(() => {
        this.tableHeight = window.innerHeight - 64 - 40 - 16 - 37 - 16 - document.getElementsByClassName("topBody")[0].offsetHeight - 24 - 40// 表格自适应高度
      }, 100)
    },
    // 查询活动账簿 接口
    getAccountBookApi() {
      this.form.loading = true
      return new Promise((resolve) => {
        getAccountBook({
          userid: this.vuex_user.base.id // 用户id
        }).then((res) => {
          this.form.loading = false
          if (res.errorcode === 0) {
            this.selectForm.year = res.basAccountbook.year // 账簿年度-回显使用
            this.selectForm.accountbookId = res.basAccountbook.accountbookId // 账簿id
            // this.selectForm.department = res.basAccountbook.department // 部门名称 查询凭证号码接口传参使用 后台要求先传空
            this.selectForm.department = '' // 部门名称 查询凭证号码接口传参使用 后台要求先传空
            this.getLastCertSnApi()// 查询凭证号码 接口
            this.getSubjectToCertificateApi()// 根据类型、用户id和账簿id查询所有在用科目(不分页) 接口
            resolve()
          } else {
            this.$Message.error(res.resultmsg)
          }
        })
      })
    },
    // 查询凭证号码 接口
    getLastCertSnApi() {
      this.form.loading = true
      return new Promise((resolve) => {
        getLastCertSn({
          accountyear: this.selectForm.year, // 账簿年度
          department: this.selectForm.department, // 部门名称
          userid: this.vuex_user.base.id // 用户id
        }).then((res) => {
          this.form.loading = false
          if (res.errorcode === 0) {
            this.selectForm.certificatesn = (res.lastcertsn + 1).toString()
            this.getAbstractByAccountBookIdAndTypeApi()// 根据类型、账簿id查询业务类型(不分页)  接口
            resolve()
          } else {
            this.$Message.error(res.resultmsg)
          }
        })
      })
    },
    // 根据类型、账簿id查询业务类型(不分页)  接口
    getAbstractByAccountBookIdAndTypeApi() {
      this.form.loading = true
      return new Promise((resolve) => {
        getAbstractByAccountBookIdAndType({
          userid: this.vuex_user.base.id, // 用户id
          accountBookId: this.selectForm.accountbookId, // 账簿id
          iszhineng: 1,
          abstractType: this.subjecttype //  摘要内容(0经费;1粮秣)
        }).then((res) => {
          this.form.loading = false
          if (res.errorcode === 0) {
            if (this.subjecttype === 0) { // 经费账
              this.selectForm.businesstypeOneList = res.abstractlist // 业务类型-经费账列表
            } else { // 粮秣账
              this.selectForm.businesstypeTwoList = res.abstractlist // 业务类型-粮秣账列表
            }
            resolve()
          } else {
            this.$Message.error(res.resultmsg)
          }
        })
      })
    },
    // 根据类型、用户id和账簿id查询所有在用科目(不分页) 接口
    getSubjectToCertificateApi() {
      this.form.loading = true
      return new Promise((resolve) => {
        getSubjectToCertificate({
          userid: this.vuex_user.base.id, // 用户id
          accountBookId: this.selectForm.accountbookId, // 账簿id
          subjectType: this.subjecttype //  摘要内容(0经费;1粮秣)
        }).then((res) => {
          this.form.loading = false
          if (res.errorcode === 0) {
            if (this.subjecttype === 0) { // 经费账
              this.subjectlistOne = res.subjectlist // 表格科目名称选择器列表 -经费账
            } else { // 粮秣账
              this.subjectlistTwo = res.subjectlist // 表格科目名称选择器列表 -粮秣账
            }
            resolve()
          } else {
            this.$Message.error(res.resultmsg)
          }
        })
      })
    },
    // 根据业务类型查找对应科目数据 接口
    getSubByAbsIdApi() {
      this.form.loading = true
      return new Promise((resolve) => {
        getSubByAbsId({
          abstractId: this.selectForm.abstractId, // 业务类型id
          abstractType: this.subjecttype // 0经费账 1粮秣账
        }).then((res) => {
          this.form.loading = false
          console.log('错误信息', res);
          if (res.retCode == 0) {
            console.log(222);
            if (this.subjecttype == 0) {//经费账
              this.dataOne = []
              for (let i = 0; i < res.data.length; i++) {
                let listOne = {
                  direction: res.data[i].direction,
                  subjectCode: res.data[i].subjectcode,
                  subjectFullName: res.data[i].subjectfullname,
                  subjectId: res.data[i].subjectid,
                  subjectName: res.data[i].subjectname,
                  payMoney: 0,
                  recMoney: 0
                }
                this.dataOne.push(listOne)
              }
              this.dataOne.forEach(element => {
                if (element.direction == 0) { // 收
                  element.recMoney = this.selectForm.oneAllMoney
                } else {// 付
                  element.payMoney = this.selectForm.oneAllMoney
                }
              })
            } else {//粮秣账
              this.dataTwo = []
              for (let i = 0; i < res.data.length; i++) {
                let listTwo = {
                  direction: res.data[i].direction,
                  subjectCode: res.data[i].subjectcode,
                  subjectFullName: res.data[i].subjectfullname,
                  subjectId: res.data[i].subjectid,
                  subjectName: res.data[i].subjectname,
                  paybean: 0,
                  payflour: 0,
                  payoil: 0,
                  payrice: 0,
                  recbean: 0,
                  recflour: 0,
                  recoil: 0,
                  recrice: 0
                }
                this.dataTwo.push(listTwo)
              }
            }
            resolve()
          } else {
            this.$Message.error(res.retMsg)
          }
        })
      })
    },

    // tabs标签页改变回调
    tabsValueChange(value) {
      if (value === 'nameOne') { // 经费账录入
        this.subjecttype = 0 // 全局标明为经费账
        this.getAccountBookApi()// 查询活动账簿 接口
        // this.getAbstractByAccountBookIdAndTypeApi()// 根据账簿id和类型查询摘要(不分页) 接口
        // this.getSubjectToCertificateApi() // 根据类型、用户id和账簿id查询所有在用科目(不分页) 接口
      } else { // 粮秣账录入
        this.subjecttype = 1// 全局标明为粮秣
        this.getAccountBookApi()// 查询活动账簿 接口
        // this.getAbstractByAccountBookIdAndTypeApi()// 根据账簿id和类型查询摘要(不分页) 接口
        // this.getSubjectToCertificateApi() // 根据类型、用户id和账簿id查询所有在用科目(不分页) 接口
      }
    },
    // 入账按钮-经费账
    addModelChangeOne() {
      // 判断表格里是否有空的值，有不往下执行
      let ass = false
      // 暂时去掉
      if (!this.selectForm.businesstypeOne) {
        this.$Message.info('业务类型不能为空')
        return
      }
      if (!this.selectForm.abstractnameOne) {
        this.$Message.info('摘要内容不能为空')
        return
      }
      if (!this.selectForm.oneAllMoney) {
        this.$Message.info('收付金额不能为空')
        return
      }
      var valueData = {
        accountbookId: this.selectForm.accountbookId, // 账簿id
        isValid: 1, // 是否在用 1-在用，0-没用
        abstractType: this.subjecttype, // 摘要内容:0经费账摘要,1粮秣账摘要,2明细摘要
        subjectType: this.subjecttype, // 科目类型:0经费账科目,1粮秣账科目,2分项核算明细
        accountYear: this.selectForm.year, // 账簿年份
        certificateSn: this.selectForm.certificatesn, // 凭证号码
        isznjzflag: 1, // 智能计账标识  1是0否 2全部
        certificateDate: new Date(this.selectForm.dataTimeOne).Format('yyyy-MM-dd'), // 入账日期  YYYY-mm-DD
        businessType: this.selectForm.businesstypeOne, // 业务类型.可以理解为摘要
        abstractName: this.selectForm.abstractnameOne, // 摘要内容
        department: this.selectForm.department, // 部门.比如一连队
        operatorname: this.vuex_user.base.name, // 登陆人姓名
        operatorid: this.vuex_user.base.id, // 用户id//登陆人Id
        certificatetype: 0, // 凭证类型0-普通，1-结转下年，2-上年转入
        remark: this.selectForm.remarkOne, // 备注
        subjectDtoList: this.dataOne
      }
      this.form.loading = true
      return new Promise((resolve) => {
        addCertificateInfo(valueData).then((res) => {
          this.form.loading = false
          if (res.errorcode === 0) {
            this.$Message.success(res.resultmsg)
            this.selectForm.businesstypeOne = ''
            this.selectForm.abstractnameOne = ''
            this.dataOne = []
            this.selectForm.oneAllMoney = null
            this.getAccountBookApi() // 查询活动账簿 接口
            resolve()
          } else {
            this.$Message.error(res.resultmsg)
          }
        })
      })
    },
    // 业务类型选择器改变回调-经费账
    selectModelChangeOne(value) {
      this.selectForm.abstractnameOne = value
      this.selectForm.businesstypeOneList.forEach(element => {
        if (element.abstractname == value) {
          this.selectForm.abstractId = element.abstractId
          this.getSubByAbsIdApi()// 根据业务类型查找对应科目数据 接口
        }
      })

    },
    // 收（付）金额改变回调
    oneAllMoneyChange() {
      if (this.selectForm.oneAllMoney != null) {
        this.selectForm.oneAllMoney = this.selectForm.oneAllMoney.toFixed(2)
      }
      this.dataOne.forEach(element => {
        if (element.direction == 0) { // 收
          element.recMoney = this.selectForm.oneAllMoney
        } else {// 付
          element.payMoney = this.selectForm.oneAllMoney
        }
      })

    },
    // 收付大米改变回调
    twoAllRiceMoneyChange() {
      if (this.selectForm.oneAllMoney != null) {
        this.selectForm.twoAllRiceMoney = this.selectForm.twoAllRiceMoney.toFixed(2)
      }
      this.dataTwo.forEach(element => {
        if (element.direction == 0) { // 收
          element.recrice = this.selectForm.twoAllRiceMoney
        } else {// 付
          element.payrice = this.selectForm.twoAllRiceMoney
        }
      })
    },
    // 收付小麦粉改变回调
    twoAllFlourMoneyChange() {
      this.selectForm.twoAllFlourMoney = this.selectForm.twoAllFlourMoney.toFixed(2)
      this.dataTwo.forEach(element => {
        if (element.direction == 0) { // 收
          element.recflour = this.selectForm.twoAllFlourMoney
        } else {// 付
          element.payflour = this.selectForm.twoAllFlourMoney
        }
      })
    },
    // 收付食油改变回调
    twoAllOilMoneyChange() {
      this.selectForm.twoAllOilMoney = this.selectForm.twoAllOilMoney.toFixed(2)
      this.dataTwo.forEach(element => {
        if (element.direction == 0) { // 收
          element.recoil = this.selectForm.twoAllOilMoney
        } else {// 付
          element.payoil = this.selectForm.twoAllOilMoney
        }
      })
    },
    // 收付大豆改变回调
    twoAllBeanMoneyChange() {
      this.selectForm.twoAllBeanMoney = this.selectForm.twoAllBeanMoney.toFixed(2)
      this.dataTwo.forEach(element => {
        if (element.direction == 0) { // 收
          element.recbean = this.selectForm.twoAllBeanMoney
        } else {// 付
          element.paybean = this.selectForm.twoAllBeanMoney
        }
      })
    },
    // 入账按钮-粮秣账
    addModelChangeTwo() {
      // 判断表格里是否有空的值，有不往下执行
      let ass = false
      // 暂时去掉
      if (!this.selectForm.businesstypeTwo) {
        this.$Message.info('业务类型不能为空')
        return
      }
      if (!this.selectForm.abstractnameTwo) {
        this.$Message.info('摘要内容不能为空')
        return
      }
      if (
        !this.selectForm.twoAllRiceMoney &&
        !this.selectForm.twoAllFlourMoney &&
        !this.selectForm.twoAllOilMoney &&
        !this.selectForm.twoAllBeanMoney
      ) {
        this.$Message.info('重量信息不能为空，至少存在一个重量信息')
        return
      }

      var valueData = {
        accountbookId: this.selectForm.accountbookId, // 账簿id
        isValid: 1, // 是否在用 1-在用，0-没用
        abstractType: this.subjecttype, // 摘要内容:0经费账摘要,1粮秣账摘要,2明细摘要
        subjectType: this.subjecttype, // 科目类型:0经费账科目,1粮秣账科目,2分项核算明细
        accountYear: this.selectForm.year, // 账簿年份
        certificateSn: this.selectForm.certificatesn, // 凭证号码
        isznjzflag: 1, // 智能计账标识  1是0否 2全部
        certificateDate: new Date(this.selectForm.dataTimeTwo).Format('yyyy-MM-dd'), // 入账日期  YYYY-mm-DD
        businessType: this.selectForm.businesstypeTwo, // 业务类型.可以理解为摘要
        abstractName: this.selectForm.abstractnameTwo, // 摘要内容
        department: this.selectForm.department, // 部门.比如一连队
        operatorname: this.vuex_user.base.name, // 登陆人姓名
        operatorid: this.vuex_user.base.id, // 用户id//登陆人Id
        certificatetype: 0, // 凭证类型0-普通，1-结转下年，2-上年转入
        remark: this.selectForm.remarkTwo, // 备注
        subjectDtoList: this.dataTwo
      }
      this.form.loading = true
      return new Promise((resolve) => {
        addCertificateInfo(valueData).then((res) => {
          this.form.loading = false
          if (res.errorcode === 0) {
            this.$Message.success(res.resultmsg)
            this.selectForm.businesstypeTwo = ''
            this.selectForm.abstractnameTwo = ''
            this.dataTwo = []
            this.selectForm.twoAllRiceMoney = null//收付大米
            this.selectForm.twoAllFlourMoney = null//收付小麦粉
            this.selectForm.twoAllOilMoney = null//收付食油
            this.selectForm.twoAllBeanMoney = null//收付大豆
            this.getAccountBookApi() // 查询活动账簿 接口
            resolve()
          } else {
            this.$Message.error(res.resultmsg)
          }
        })
      })
    },
    // 业务类型选择器改变回调-粮秣账
    selectModelChangeTwo(value) {
      this.selectForm.abstractnameTwo = value
      this.selectForm.businesstypeTwoList.forEach(element => {
        if (element.abstractname == value) {
          this.selectForm.abstractId = element.abstractId
          this.getSubByAbsIdApi()// 根据业务类型查找对应科目数据 接口
        }
      })
    },
    // 收方(大米)改变回调-粮秣账
    recriceTwo(index, value) {
      this.dataTwo[index].recrice = value
    },
    // 收方(小麦粉)改变回调-粮秣账
    recflourTwo(index, value) {
      this.dataTwo[index].recflour = value
    },
    // 收方(食油)改变回调-粮秣账
    recoilTwo(index, value) {
      this.dataTwo[index].recoil = value
    },
    // 收方(大豆)改变回调-粮秣账
    recbeanTwo(index, value) {
      this.dataTwo[index].recbean = value
    },
    // 付方(大米)改变回调-粮秣账
    payriceTwo(index, value) {
      this.dataTwo[index].payrice = value
    },
    // 付方(小麦粉)改变回调-粮秣账
    payflourTwo(index, value) {
      this.dataTwo[index].payflour = value
    },
    // 付方(食油)改变回调-粮秣账
    payoilTwo(index, value) {
      this.dataTwo[index].payoil = value
    },
    // 付方(大豆)改变回调-粮秣账
    paybeanTwo(index, value) {
      this.dataTwo[index].paybean = value
    },
    // 首页返回按钮
    returnHome() {
      this.$router.push('/home')
    }
  }
}
</script>
<style lang="less" scoped>
.topBody {
  display: flex;
  margin-bottom: 10px;
  align-items: center;
  flex-wrap: wrap;

  .topBodyItem {
    margin-right: 12px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;

    .itemSpan {
      white-space: nowrap;
      width: 80px;
      text-align: right;
      font-size: 14px;
      color: rgba(0, 0, 0, 0.85) !important;
      margin-right: 10px;
    }

    .itemImport {
      width: 200px;
    }
  }
}

// 图表上方tabs标签样式
// 当我们需要覆盖element-ui中的样式时只能通过深度作用选择器-样式穿透
::v-deep .tableInput {
  .ivu-input-number {
    .ivu-input-number-input-wrap {
      .ivu-input-number-input {
        text-align: right;
        padding-right: 26px;
      }
    }
  }
}
</style>
